package cn.openea.perpartner.componet.web.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.openea.perpartner.componet.handler.ChainHandler;
import cn.openea.perpartner.componet.web.entity.ClicksLog;
import cn.openea.perpartner.componet.web.entity.HisShareLog;
import cn.openea.perpartner.componet.web.entity.InsShareLog;
import cn.openea.perpartner.componet.web.mapper.ClicksLogMapper;
import cn.openea.perpartner.componet.web.service.IClicksLogService;
import cn.openea.perpartner.componet.web.service.IHisShareLogService;
import cn.openea.perpartner.componet.web.service.InsShareLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 分享次数记录表(ShareNumLog)表服务实现类
 *
 * @author Weird077
 * @since 2023-03-01 15:40:13
 */
@Service
public class ClicksLogServiceImpl extends ServiceImpl<ClicksLogMapper, ClicksLog> implements IClicksLogService, ChainHandler {
    @Resource
    private IHisShareLogService hisShareLogService;
    @Resource
    private InsShareLogService insShareLogService;

    @Override
    public boolean execute(Map<String, Object> params) {
        ClicksLog clicksLog = new ClicksLog();
        String shareId = (String) params.get("shareId");
        clicksLog.setShareId(shareId);
        clicksLog.setUserId((String) params.get("userId"));
        clicksLog.setNickName((String) params.get("nickName"));
        InsShareLog insShareLog = insShareLogService.getById(shareId);
        if (BeanUtil.isNotEmpty(insShareLog)) {
            clicksLog.setSourceId(insShareLog.getSourceId());
        } else {
            HisShareLog hisShareLog = hisShareLogService.getById(shareId);
            if (BeanUtil.isNotEmpty(hisShareLog)) {
                clicksLog.setSourceId(hisShareLog.getSourceId());
            }
        }
        return save(clicksLog);
    }
}

